package com.xinxi11.project.qx.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.google.common.collect.Maps;
import com.xinxi11.module.core.web.struts2.Struts2ActionSupport;
import com.xinxi11.module.core.web.struts2.Struts2Utils;
import com.xinxi11.project.qx.beans.QxUser;
import com.xinxi11.project.qx.services.IQxUserService;

/**
* 权限用户查询
*
* @author 李国江
* @date 2011-4-29
*/
public class QxUserAction extends Struts2ActionSupport {

	private static final long serialVersionUID = -5945595103982520013L;

	private static Map<String, String> userJson = Maps.newHashMap();

	private IQxUserService qxUserService;

	/** 查询当前用户在模块下的部门权限 */
	public void findUser() {
		String userName = getSid();
		if (StringUtils.isNotBlank(userName)) {
			if (userJson.containsKey(userName)) {
				Struts2Utils.renderJson(userJson.get(userName));
			} else {
				List<QxUser> userList = qxUserService.findUserLikeName(userName);
				String json = userListJson(userList);
				userJson.put(userName, json);
				Struts2Utils.renderJson(json);
			}

		}
	}
	
	/**  部门人员树,传入参数是要查询的部门Ids */
	public void ajaxUserTree(){
		//部门IDs,以','为分割
		String unitIds=getSid();
		String userTreeJson=qxUserService.findUserTree(unitIds);
		Struts2Utils.renderJson(userTreeJson);
	}

	private String userListJson(List<QxUser> unitLis) {
		StringBuilder jsonData = new StringBuilder();

		// TODO 封装用户列表到json数据

		return jsonData.toString();
	}

}
